package wps

import (
	"github.com/zzl/go-com/com"
	"github.com/zzl/go-com/ole"
	"github.com/zzl/go-win32api/v2/win32"
	"syscall"
	"unsafe"
)

var CLSID_DebugTools = syscall.GUID{0x45540F00, 0x5750, 0x5300,
	[8]byte{0x4B, 0x49, 0x4E, 0x47, 0x53, 0x4F, 0x46, 0x55}}

type DebugTools struct {
	DebugTools_
}

func NewDebugTools(pDisp *win32.IDispatch, addRef bool, scoped bool) *DebugTools {
	if pDisp == nil {
		return nil
	}
	p := &DebugTools{DebugTools_{ole.OleClient{pDisp}}}
	if addRef {
		pDisp.AddRef()
	}
	if scoped {
		com.AddToScope(p)
	}
	return p
}

func NewDebugToolsFromVar(v ole.Variant, addRef bool, scoped bool) *DebugTools {
	return NewDebugTools(v.IDispatch(), addRef, scoped)
}

func NewDebugToolsInstance(scoped bool) (*DebugTools, error) {
	var p *win32.IDispatch
	hr := win32.CoCreateInstance(&CLSID_DebugTools, nil,
		win32.CLSCTX_INPROC_SERVER|win32.CLSCTX_LOCAL_SERVER,
		&IID_DebugTools_, unsafe.Pointer(&p))
	if win32.FAILED(hr) {
		return nil, com.NewError(hr)
	}
	return NewDebugTools(p, false, scoped), nil
}
